package com.springboot.service.impl;

import com.springboot.mapper.UserMapper;
import com.springboot.pojo.Count;
import com.springboot.pojo.User;
import com.springboot.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public Count login(User user) {
        Count count=new Count();
        String Station = user.getStation();
        String Identity = user.getIdentity();
        int Password = user.getPassword();
        User Info = userMapper.userSelect(Station, Identity);
        User loginInfo = userMapper.userLogin(Station, Identity, Password);
        if (Info != null) {
            if (Info.getCount() > 3) {
                count.setCount(Info.getCount());
                count.setNumber(-2);
                return count;
            } else {
                if (loginInfo == null) {
                    userMapper.countApdate(Info.getStation(),Info.getIdentity());
                    User apdateInfo = userMapper.userSelect(Station, Identity);
                    count.setCount(apdateInfo.getCount());
                    count.setNumber(0);
                    return count;
                } else {
                    userMapper.countClear(Info.getStation(),Info.getIdentity());
                    count.setCount(Info.getCount());
                    count.setNumber(1);
                    return count;
                }
            }
        }
        count.setNumber(-1);
        return count;
    }

    @Override
    public boolean forget(User user) {
        String Station = user.getStation();
        String Identity = user.getIdentity();
        User Info = userMapper.userSelect(Station, Identity);
        if (Info!=null){
            Info.setCreateTime(LocalDateTime.now());
            return userMapper.insertForgetInfo(Info);
        }
        return false;
    }

}
//
//    @Override
//    public boolean register(User user) throws Exception {
//        boolean a=false;
//        String name = user.getName();
//        String phone = user.getPhone();
//        String address = user.getAddress();
//        String account = user.getAccount();
//        String password = user.getPassword();
//        LocalDateTime createTime=LocalDateTime.now();
//        try {
//            userMapper.userRegister(name, phone, address, account, password,createTime);
//            a=true;
//
//        } catch (Exception e) {
//
//        }
//        return a;
//    }
//
//    @Override
//    public List<User> getByuseraccount(Integer account) {
//        return userMapper.getByuserid(account);
//    }

